﻿using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using MYData.Entity.DomainModels;
using MYData.Entity.Project;

namespace MYData.WebApi.Controllers.MysqlData
{
    [Route("api/[controller]")]
    [ApiController]
    public class TableDataController : ControllerBase
    {
        /// <summary>
        /// 依赖注入
        /// </summary>
        public readonly ISqlSugarClient _client;
        public TableDataController(IConfiguration configuration)
        {
            _client = new SqlSugarClient(new ConnectionConfig
            {
                DbType = DbType.MySql,
                ConnectionString = "Data Source=124.223.90.212;Database=netcoredev;User ID=root;Password=!@#$qwer1234;pooling=true;port=2007;sslmode=none;CharSet=utf8mb4;"
                //ConnectionString = configuration.GetConnectionString("DbConnectionString")
            });
        }
        /// <summary>
        /// SqlSugar建库建表
        /// </summary>
        [HttpPost]
        public void DataBase()
        {
            //_client.DbMaintenance.CreateDatabase();
            //_client.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(Tb_Project_Audit));
            //_client.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(Tb_Project_Fundtemplate));
            //_client.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(Tb_Project_Templatesubject_Relationship));
            //_client.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(tb_project_workflowstep));
            //_client.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(tb_project_workflowtable));
            //_client.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(UserInfo));
            //_client.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(tb_project_expectedresults));
            //_client.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(tb_project_fundingsubject_realition));
            //_client.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(Tb_Project_Fundtemplate_Item));
            //_client.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(tb_project_participationer));
            //_client.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(tb_project_planontarget));
            //_client.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(tb_project_projectpersonnel));
            //_client.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(tb_project_type_template)); _client.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(tb_project_baseinfo)); _client.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(tb_project_appendix)); _client.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(tb_project_sourceinfo)); _client.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(Tb_Project_Department)); _client.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(tb_project_tsinfo));
            _client.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(tb_project_fundingtemplatesource_relation));
        }
    }
}
